# 导包
import unittest, requests


# 创建测试类
class TestIHRMLogin(unittest.TestCase):
    # 定义测试固件
    def setUp(self):
        # 实例化session
        self.session = requests.Session()

    def tearDown(self):
        # 关闭session
        self.session.close()

    # 定义测试函数
    def test01_login_success(self):
        # 使用session发送登陆请求
        response = self.session.post(url="http://ihrm-test.itheima.net/api/sys/login",
                                     headers={"Content-Type": "application/json"},
                                     json={"mobile": "13800000002", "password": "123456"})
        # 打印
        print(response.json)
        # 断言
        self.assertEqual(200, response.status_code)  # 断言响应状态码
        self.assertEqual(True, response.json().get("success"))  # 断言success
        self.assertEqual(10000, response.json().get("code"))  # 断言code
        self.assertIn("操作成功", response.json().get("message"))  # 断言message
